etcdctl --endpoints=https://192.168.1.81:2379 \
  --cert=/etc/kubernetes/pki/etcd/server.crt \
  --key=/etc/kubernetes/pki/etcd/server.key \
  --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  endpoint health


etcdctl --endpoints=https://192.168.1.82:2379 \
  --cert=/etc/kubernetes/pki/etcd/server.crt \
  --key=/etc/kubernetes/pki/etcd/server.key \
  --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  endpoint health


etcdctl --endpoints=https://k8s-cluster-196-master01:2379,https://k8s-cluster-196-master02:2379,https://k8s-cluster-196-master03:2379 \
  --cert=/etc/kubernetes/pki/etcd/server.crt \
  --key=/etc/kubernetes/pki/etcd/server.key \
  --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  endpoint health


# 备份etcd数据
ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 \
  --cert=/etc/kubernetes/pki/etcd/server.crt \
  --key=/etc/kubernetes/pki/etcd/server.key \
  --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  snapshot save /root/backup.db


# 查看etcd节点列表
ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 \
  --cert=/etc/kubernetes/pki/etcd/server.crt \
  --key=/etc/kubernetes/pki/etcd/server.key \
  --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  member list


# 移除etcd节点
ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 \
  --cert=/etc/kubernetes/pki/etcd/server.crt \
  --key=/etc/kubernetes/pki/etcd/server.key \
  --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  member remove 99bd7313390d212f


# 停止节点服务
#systemctl stop etcd
systemctl stop kubelet
docker rm -f `docker ps -a |grep etcd|awk '{print $1}'`

# 清除etcd数据
mv /var/lib/etcd etcd.bak

# 重新添加etcd节点
ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 \
  --cert=/etc/kubernetes/pki/etcd/server.crt \
  --key=/etc/kubernetes/pki/etcd/server.key \
  --cacert=/etc/kubernetes/pki/etcd/ca.crt \
  member add k8s-cluster-196-master03 --peer-urls=https://192.168.1.83:2380


# 启动etcd
systemctl start kubelet
reboot


# 恢复数据
etcdctl snapshot restore backup.db \
--name k8s-cluster-196-master01 \
--initial-cluster 'k8s-cluster-196-master01=https://192.168.1.81:2380' \
--initial-advertise-peer-urls https://192.168.1.81:2380 \
--data-dir /var/lib/etcd \
--skip-hash-check=true


etcdctl snapshot restore backup.db \
--name k8s-cluster-196-master02 \
--initial-cluster 'k8s-cluster-196-master02=https://192.168.1.82:2380,k8s-cluster-196-master03=https://192.168.1.83:2380,k8s-cluster-196-master01=https://192.168.1.81:2380' \
--initial-advertise-peer-urls https://192.168.1.82:2380 \
--data-dir /var/lib/etcd \
--skip-hash-check=true

etcdctl snapshot restore backup.db \
--name k8s-cluster-196-master03 \
--initial-cluster 'k8s-cluster-196-master02=https://192.168.1.82:2380,k8s-cluster-196-master03=https://192.168.1.83:2380,k8s-cluster-196-master01=https://192.168.1.81:2380' \
--initial-advertise-peer-urls https://192.168.1.83:2380 \
--data-dir /var/lib/etcd \
--skip-hash-check=true